package com.ruoyi.web.controller.jl;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.base.Result;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.support.Convert;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.jl.domain.GameLog;
import com.ruoyi.jl.service.IGameLogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 玩家游玩日志 控制层
 * 
 * @author wh
 * @date 2019-04-29
 */
@Slf4j
@Controller
@RequestMapping("/jl/gameLog")
public class GameLogController extends BaseController {
    private String prefix = "jl/gameLog";
	
	private final IGameLogService gameLogService;

	@Autowired
	public GameLogController(IGameLogService gameLogService) {
		this.gameLogService = gameLogService;
	}

	/**
	*  列表页
	*/
	@RequiresPermissions("jl:gameLog:view")
	@GetMapping
	public String gameLog(){
	    return prefix + "/gameLog";
	}

	/**
	 * 新增页
	 */
	@GetMapping("/add")
	public String add(){
		return prefix + "/add";
	}

	/**
	 * 编辑页
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap){
		GameLog gameLog = gameLogService.getById(id);
		mmap.put("gameLog", gameLog);
		return prefix + "/edit";
	}
	
	/**
	 * 查询玩家游玩日志列表
	 */
	@RequiresPermissions("jl:gameLog:list")
	@PostMapping("/list")
	@ResponseBody
	public Result list(GameLog gameLog){
		startPage();
        List<GameLog> list = gameLogService.list(gameLog);
		return Result.success(getDataTable(list));
	}

	/**
	 * 新增保存玩家游玩日志
	 */
	@RequiresPermissions("jl:gameLog:add")
	@Log(title = "玩家游玩日志", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public Result addSave(GameLog gameLog){
		gameLogService.save(gameLog);
		return Result.success();
	}

	/**
	 * 修改保存玩家游玩日志
	 */
	@RequiresPermissions("jl:gameLog:edit")
	@Log(title = "玩家游玩日志", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public Result editSave(GameLog gameLog){
		gameLogService.updateById(gameLog);
		return Result.success();
	}
	
	/**
	 * 删除玩家游玩日志
	 */
	@RequiresPermissions("jl:gameLog:remove")
	@Log(title = "玩家游玩日志", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public Result remove(String ids){
		Long[] longIds = Convert.toLongArray(ids);
		gameLogService.removeByIds(Arrays.asList(longIds));
		return Result.success();
	}

	/**
	 * 导出玩家游玩日志列表
	 */
	@RequiresPermissions("jl:gameLog:export")
	@PostMapping("/export")
	@ResponseBody
	public Result export(GameLog gameLog){
		List<GameLog> list = gameLogService.list(gameLog);
		ExcelUtil<GameLog> util = new ExcelUtil<>(GameLog.class);
		util.exportExcel(list, "gameLog");
		return Result.success();
	}
}
